/**
 * 
 */
package cn.softTank.BpelModelImpl;

import org.dom4j.Element;

import cn.softTank.BpelModel.Sources;
import cn.softTank.BpelModel.Targets;

/**
 * @author Yuzone (smartzxy@gmail.com)
 * 
 */
public abstract class ActivityImpl extends ExtensibleElementImpl implements
		cn.softTank.BpelModel.Activity {

	private String name;
	private Sources sources;
	private Targets targets;
	private boolean suppressJoinFailure;
	private boolean setSuppressJoinFailure = false;

	/*
	 * (non-Javadoc)
	 * 
	 * @see cn.softTank.BpelModel.Activity#getName()
	 */
	@Override
	public String getName() {
		return name;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see cn.softTank.BpelModel.Activity#getSources()
	 */
	@Override
	public Sources getSources() {
		return sources;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see cn.softTank.BpelModel.Activity#getTargets()
	 */
	@Override
	public Targets getTargets() {
		return targets;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see cn.softTank.BpelModel.Activity#isSetSuppressJoinFailure()
	 */
	@Override
	public boolean isSetSuppressJoinFailure() {
		return setSuppressJoinFailure;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see cn.softTank.BpelModel.Activity#isSuppressJoinFailure()
	 */
	@Override
	public boolean isSuppressJoinFailure() {
		return suppressJoinFailure;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see cn.softTank.BpelModel.Activity#setName(java.lang.String)
	 */
	@Override
	public void setName(String name) {
		this.name = name;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * cn.softTank.BpelModel.Activity#setSources(cn.softTank.BpelModel.Sources)
	 */
	@Override
	public void setSources(Sources sources) {
		this.sources = sources;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see cn.softTank.BpelModel.Activity#setSuppressJoinFailure(boolean)
	 */
	@Override
	public void setSuppressJoinFailure(boolean suppressJoinFailure) {
		this.suppressJoinFailure = suppressJoinFailure;
		setSuppressJoinFailure = true;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * cn.softTank.BpelModel.Activity#setTargets(cn.softTank.BpelModel.Targets)
	 */
	@Override
	public void setTargets(Targets targets) {
		this.targets = targets;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see cn.softTank.BpelModel.Activity#unsetSuppressJoinFailure()
	 */
	@Override
	public void unsetSuppressJoinFailure() {
		setSuppressJoinFailure = false;
	}

	@Override
	public Element toElement() {
		node=super.toElement();
		if(name!=null)
			node.addAttribute("name", name);
		if(setSuppressJoinFailure)
			if(suppressJoinFailure)
				node.addAttribute("suppressJoinFailure", "yes");
			else
				node.addAttribute("suppressJoinFailure", "no");
		if(sources!=null)
			node.add(sources.toElement());
		if(targets!=null)
			node.add(targets.toElement());
		return node;
	}

	@Override
	public String toXml() {
		return null;
	}
}
